package com.heifeng.cloudshelf.mvp.programme.activity;

import android.app.Activity;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;

import android.view.View;

import com.heifeng.cloudshelf.R;
import com.heifeng.cloudshelf.base.BaseActivity;
import com.heifeng.cloudshelf.mvp.programme.contract.VideoPlayerActivityContract;
import com.heifeng.cloudshelf.mvp.programme.presenter.VideoPlayerActivityPresenter;
import com.heifeng.cloudshelf.widget.CustomVideoPlayer;

import butterknife.BindView;
import butterknife.OnClick;
import cn.jzvd.Jzvd;

/*
*视频播放
 */
public class VideoPlayerActivity extends BaseActivity<VideoPlayerActivityPresenter> implements VideoPlayerActivityContract.View {
    @BindView(R.id.videoplayer)
    CustomVideoPlayer videoPlayer;
    private String videoUrl;

    public static void StartActivity(Activity activity,String url) {
        Intent intent = new Intent(activity, VideoPlayerActivity.class);
        intent.putExtra("video",url);
        activity.startActivity(intent);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_video_player;
    }

    @Override
    protected void initEventAndData() {
        videoUrl = getIntent().getStringExtra("video");

        mPresenter.initVideoPlayer(videoPlayer);
    }

    @Override
    public String getVideoUrl() {
        return videoUrl;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    public CustomVideoPlayer getPlayer() {
        return videoPlayer;
    }

    @Override
    public void onBackPressed() {
        if (Jzvd.backPress()) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onPause() {
        super.onPause();
        Jzvd.releaseAllVideos();
    }

    @OnClick({R.id.l_back})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.l_back:
                onBackPressed();
                break;
        }
    }
}
